#include <iostream>
#include <pthread.h>
#include "ThreadPool.hpp"
#include "Task.hpp"
#include <ctime>

int main()
{
    //ThreadPool<Task> *tp = new ThreadPool<Task>(5);
    //tp->Start(); // 线程池直接准备好，等待调用  创建一批进程
    ThreadPool<Task>::GetInstance()->Start();

    srand(time(nullptr) ^ getpid());

    while (true)
    {
        // 1.主线程构建任务
        int x = rand() % 10 + 1;
        usleep(10);
        int y = rand() % 5;
        char op = opers[rand() % opers.size()];
        //std::cout << "OP is "<< op << std::endl;
        
        Task t(x, y , op);
        //tp->Push(t);
        ThreadPool<Task>::GetInstance()->Push(t);

        // 交给线程池处理
        std::cout << "main make a task is " << t.GetTask() << std::endl;

        sleep(1);
        //std::cout << "main thread wait task..." << std::endl;
    }
    return 0;
}
